package com.yoyo.itravel.service.impl;

import com.yoyo.itravel.bean.PlanType;
import com.yoyo.itravel.dao.IPlanTypeDao;
import com.yoyo.itravel.exceptions.PlanTypeException;
import com.yoyo.itravel.service.IPlanTypeService;
import com.yoyo.itravel.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

/**
 * @author liuchaojie
 * @version 1.0
 * @Description 飞机类型服务层接口实现类【服务层】
 * @date 2020/6/18 19:05
 */
@Service
public class PlanTypeServiceImpl implements IPlanTypeService {
    @Autowired
    private IPlanTypeDao planTypeDao;

    /**
     * 新增机型信息
     * @param planType
     * @return
     * @throws PlanTypeException
     */
    @Override
    public boolean addPlanType(PlanType planType) throws PlanTypeException {
        if(null == planType){
            throw new PlanTypeException("传入机型信息为空!...");
        }
        try {
            return planTypeDao.addPlanType(planType);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new PlanTypeException("新增机型信息!...");
        }
    }

    /**
     * 删除一条机型信息
     * @param planTypeId
     * @return
     * @throws PlanTypeException
     */
    @Override
    public boolean deleteByPlanType(String planTypeId) throws PlanTypeException {
        try {
            return planTypeDao.deleteByPlanType(planTypeId);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new PlanTypeException("删除一条机型信息失败！...");
        }
    }

    /**
     * 查找所有机型信息
     * @return
     * @throws PlanTypeException
     */
    @Override
    public List<PlanType> selectAll() throws PlanTypeException {
        try {
            return planTypeDao.selectAll();
        } catch (SQLException e) {
            e.printStackTrace();
            throw new PlanTypeException("查找所有机型信息失败！...");
        }
    }

    /**
     * 修改根据机型Id机型信息
     * @param planType
     * @return
     * @throws PlanTypeException
     */
    @Override
    public boolean changePlanType(PlanType planType) throws PlanTypeException {
        try {
            return planTypeDao.changePlanType(planType);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new PlanTypeException("修改根据机型Id机型信息失败！...");
        }
    }
}
